<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style>
            .menu {
                width: 100px;
                height: 200px;
                background-color: palegreen;
                /* 先进行定位操作，才能获取修改他相关的值 */
                position: fixed;
                display: none;
            }
        </style>
    </head>
    <body>
        <div class="menu">
            <p>菜单1</p>
            <p>菜单2</p>
            <p>菜单3</p>
        </div>
        <script>
            //获取菜单的元素
            let menu = document.querySelector(".menu");
            document.oncontextmenu = (event)/*全部的属性*/ => {
                event.preventDefault();//先阻止浏览器默认的事件
                let mouseX = event.pageX;//获取鼠标的据X轴线距离
                let mouseY = event.pageY;//获取鼠标的据y轴线距离
                menu.style.left = mouseX + "px";//反点后更改他的属性
                menu.style.top = mouseY + "px";
                menu.style.display = "block";
            };
            //鼠标点下去后更改属性
            document.onmousedown = () => {
                menu.style.display = "none";
            };
        </script>
    </body>
</html>
